import { ElMessage } from 'element-plus'

interface AppState {
    // 折叠菜单
    collapse: boolean,
    // 显示页脚
    footer: boolean,
    // 固定toolheader
    fixedHeader: boolean,
    layout: LayoutType,
    logo: boolean,
    // 是否是移动端
    mobile: boolean,
    // 路由跳转loading
    pageLoading: boolean,
    title: string,
}

export const useAppStore = defineStore('app', {
    state: (): AppState => {
        return {
            collapse: false,
            footer: true,
            fixedHeader: true,
            layout: 'classic',
            logo: true,
            mobile: false,
            title: 'TEST ADMIN',
        }
    },
    getters: {
        getCollapse(): boolean {
            return this.collapse
        },
        getFooter(): boolean {
            return this.footer
        },
        getFixedHeader(): boolean {
            return this.fixedHeader
        },
        getLayout(): LayoutType {
            return this.layout
        },
        getLogo(): boolean {
            return this.logo
        },
        getMobile(): boolean {
            return this.mobile
        },
        getPageLoading(): boolean {
            return this.pageLoading
        },
        getTitle(): string {
            return this.title
        }
    },
    actions: {
        setCollapse(collapse: boolean) {
            this.collapse = collapse
        },
        setFooter(footer: boolean) {
            this.footer = footer
        },
        setFixedHeader(fixedHeader: boolean) {
            this.fixedHeader = fixedHeader
        },
        setLayout(layout: LayoutType) {
            if (this.mobile && layout !== 'classic') {
                ElMessage.warning('移动端模式下不支持切换其它布局')
                return
              }
            this.layout = layout
        },
        setLogo(logo: boolean) {
            this.logo = logo
        },
        setMobile(mobile: boolean) {
            this.mobile = mobile
        },
        setPageLoading(pageLoading: boolean) {
            this.pageLoading = pageLoading
        },
        setTitle(title: string) {
            this.title = title
        },
    }
})